/*
 * Created by JFormDesigner on Fri Nov 08 12:33:33 CST 2024
 */

package com.hafu.view.kehu;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import com.hafu.model.Khinfo;
import com.hafu.service.KhinfoService;
import com.hafu.util.StringUtil;
import net.miginfocom.swing.*;

/**
 * @author TPY
 */
public class AddKeHuFrm extends JFrame {
    private KhinfoService khinfoService = new KhinfoService();
    public AddKeHuFrm() {
        initComponents();
    }

    private void button1(ActionEvent e) {
        // TODO add your code here 添加客户信息事件
        String name = textField1.getText();
        String tel = textField2.getText();
        if (StringUtil.isEmpty(name)) {
            JOptionPane.showMessageDialog(null, "客户姓名不能为空");
            return;
        }
        if (StringUtil.isEmpty(tel)){
            JOptionPane.showMessageDialog(null, "客户电话不能为空");
            return;
       }
        Khinfo khinfo = new Khinfo();
        khinfo.setName(name);
        khinfo.setTel(tel);
//        Khinfo khinfo = new Khinfo(name,tel);
        Boolean aBoolean = khinfoService.addKhinfo(khinfo);
        if (aBoolean){
            JOptionPane.showMessageDialog(null, "添加成功");
            this.dispose();
        }else {
            JOptionPane.showMessageDialog(null, "添加失败");
        }

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        textField2 = new JTextField();
        button1 = new JButton();

        //======== this ========
        setTitle("\u6dfb\u52a0\u5ba2\u6237\u8868\u5355");
        Container contentPane = getContentPane();
        contentPane.setLayout(new MigLayout(
            "hidemode 3",
            // columns
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]",
            // rows
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]"));

        //---- label1 ----
        label1.setText("\u5ba2\u6237\u540d\u5b57");
        contentPane.add(label1, "cell 4 3 1 3");
        contentPane.add(textField1, "cell 7 4 15 1");

        //---- label2 ----
        label2.setText("\u5ba2\u6237\u7535\u8bdd");
        contentPane.add(label2, "cell 4 7");
        contentPane.add(textField2, "cell 7 7 15 1");

        //---- button1 ----
        button1.setText("\u63d0\u4ea4");
        button1.addActionListener(e -> button1(e));
        contentPane.add(button1, "cell 5 13 10 1");
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JTextField textField2;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
